package com.stormrage.edu.serv.exam.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stormrage.edu.dao.exam.ExmTermScoreDao;
import com.stormrage.edu.serv.exam.ExmTermScoreServ;
import com.stormrage.entity.exam.ExmTermScore;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: ExmTermScoreServImpl.java
 * @Package com.stormrage.edu.serv.exam.impl
 * @Description: 学期题目分数 Service
 * @author www.stormragetech.com
 * @date 2016年5月14日
 * @version V1.0
 */
@Service
public class ExmTermScoreServImpl implements ExmTermScoreServ {

	private static final Logger logger = LoggerFactory.getLogger(ExmTermScoreServImpl.class);

	@Autowired
	private ExmTermScoreDao exmTermScoreDao;

	@Override
	public Integer create(final ExmTermScore arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 create 】-【 STARTED 】");

		Integer index = exmTermScoreDao.create(arg0);

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 create 】-【 COMPLETED 】");
		return index;

	}

	@Override
	public void update(final ExmTermScore arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 update 】-【 STARTED 】");

		ExmTermScore entity = queryByTermId(arg0.getTermId());

		if (null == entity)
			create(arg0);
		else {
			arg0.setId(entity.getId());
			exmTermScoreDao.update(arg0);
		}

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 update 】-【 COMPLETED 】");

	}

	@Override
	public ExmTermScore queryById(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 queryById 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", arg0);

		ExmTermScore entity = exmTermScoreDao.queryById(map);

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 queryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public ExmTermScore queryByTermId(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 queryByTermId 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("termId", arg0);

		ExmTermScore entity = exmTermScoreDao.queryByTermId(map);

		logger.debug(" 【 Serv 】- 【 ExmTermScoreServ 】- 【 queryByTermId 】-【 COMPLETED 】");
		return entity;

	}

}
